#ifndef _ILOG_H_
#define _ILOG_H_
#define _THREADLOG_		//定义是否用于多线程
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdarg.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#define ulong   unsigned long
#define uint    unsigned int


#if ( defined _THREADLOG_ )
	#include <pthread.h>
	#define TLS __thread
#else 
	#define TLS
#endif

#define LOGFILEMAXLEN			1024
#define LOGBUFLEN				2048
#define	LOGFILENAMEMAXLEN		1024 
#define LOGDEFAULTLEVEL			LOG_LEVEL_INFO

#define LOG_LEVEL_DEBUG			0
#define LOG_LEVEL_WARN			1
#define LOG_LEVEL_INFO			2
#define LOG_LEVEL_ERROR			3
#define LOG_LEVEL_FATAL			4

#define PROCESSID	getpid()
#define	THREADID	pthread_self()
#define ADDNEWLINE( __buf__, __usedlen__, __remainlen__ ) \
   	sprintf(__buf__, "\n"); \
	__buf__++; \
	__usedlen__++; \
	__remainlen__--

int SetLogFile( char *format, ...);
int SetLogLevel( int loglevel );

/* 输入到文件的接口 */
int FatalLog( char *filename, ulong fileline, char *format, ...);
int ErrorLog( char *filename, ulong fileline, char *format, ...);
int InfoLog( char *filename, ulong fileline, char *format, ...);
int DebugLog( char *filename, ulong fileline, char *format, ...);
int WarnLog( char *filename, ulong fileline, char *format, ...);

typedef struct 
{
	char PathFielTemplate[LOGFILEMAXLEN + 1];
	char PathFileName[LOGFILENAMEMAXLEN + 1];
	char MsgBuf[LOGBUFLEN + 1];
	char MsgTemplate[LOGBUFLEN + 1];
	int LogLevel;
}LogEnv;

#endif


